package resilienceManager.qmul.gemom;
import java.awt.Color;

import no.geosoft.cc.geometry.Geometry;
import no.geosoft.cc.graphics.GObject;
import no.geosoft.cc.graphics.GPosition;
import no.geosoft.cc.graphics.GSegment;
import no.geosoft.cc.graphics.GStyle;
import no.geosoft.cc.graphics.GText;

/**
 * the RectObject, used to draw the item in the scence
 * 
 * COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu Jinfu Wang------------QMUL
 * @version 1.0 
 */

public class RectObject extends GObject {
	private NodeObject  parent_;
	private double      x_, y_;
	private double 		w_,h_;
	private GSegment    Rectangle_;
	private GSegment    line_;


	RectObject (String name, GObject parent, double x, double y, double w, double h)
	{
		parent_ = parent instanceof NodeObject ? (NodeObject) parent : null;

		x_ = x;
		y_ = y;
		
		w_=w;
		h_=h;
		

		line_ = new GSegment();
		addSegment (line_);

		Rectangle_ = new GSegment();
		addSegment (Rectangle_);

		Rectangle_.setText (new GText (name, GPosition.MIDDLE));

		setStyle (new GStyle());

		parent.add (this);
		
		//getStyle().setBackgroundColor (Color.RED);
	}


	double getX()
	{
		return x_;
	}


	double getY()
	{
		return y_;
	}
	
	double getW()
	{
		return w_;
	}
	
	double getH()
	{
		return h_;
	}
	
	public GSegment getSegment(){
		return Rectangle_;
	}



	public void draw()
	{
		if (parent_ != null) 
			line_.setGeometry (parent_.getX(), parent_.getY(), x_, y_);
		
		Rectangle_.setGeometryXy (Geometry.createRectangle(x_, y_, w_, h_));
	}

}
